<template>
  <div class="boxs" ref="animationRef1">
    <titles :title="props.info.text" style="justify-content: left" />
    <div class="subTitle" v-if="props.info.subTitle">——{{ props.info.subTitle }}</div>
    <div class="text-max-box">
      <textMax v-if="props.info.remarks" :data="props.info.remarks" :maxLen="108" :flag="false" />
    </div>
    <div
      style="cursor: pointer"
      class="preface-content"
      @mouseenter="imgEnter(0, props.info.children)"
      @mouseleave="imgLeave(0, props.info.children)"
      @click="pathChild(props.info, 0)"
    >
      <div class="preface-left">
        <img
          v-if="props.info.children[0].value"
          class="preface-left-img"
          :src="$filters.getLinkUrl(props.info.children[0].value + '?imageView2/1/w/600/h/358/format/webp')"
          alt=""
        />
        <div v-else class="preface-left-img">
          <UnitImageNull></UnitImageNull>
        </div>

        <div class="shadow"></div>
      </div>
      <div class="preface-right">
        <div>
          <div>
            <span
              :class="'titleText' + props.info.children[0].id"
              class="title1"
              :style="{
                fontSize: store.styleInfo.mintitleSize,

                color: store.styleInfo.fontColor,
              }"
              >{{ props.info.children[0].text }}</span
            >
          </div>

          <div class="line" :class="'line' + props.info.children[0].id"></div>
          <div class="subTitle" v-if="props.info.children[0].subTitle">——{{ props.info.children[0].subTitle }}</div>
        </div>
        <span
          v-html="getTextHtmlBr(props.info.children[0].remarks)"
          class="left-title"
          :style="{
            fontSize: store.styleInfo.contentSize,
          }"
        ></span>
        <div
          :style="{
            fontSize: store.styleInfo.mintitleSize,
            color: '#fff',
          }"
          class="left-btn flex-c-c-c"
        >
          <div class="btn-img">
            <buttonIcon />
          </div>
          <span>查看全部</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// @ts-nocheck
import { onMounted, ref } from 'vue';
import { pathList, pathListLoop } from '../route';
import { getTextHtmlBr } from '@/utils/minxin';
import { urls } from '@/utils/request/upload';
import titles from '@/components/title/title.vue';
import buttonIcon from '@/components/title/buttonIcon.vue';
import textMax from './component/textMax2.vue';
import { useProjectStore } from '@/store';
import { useRouter, useRoute } from 'vue-router';
import { imgEnter, imgLeave } from './component/hover';
import UnitImageNull from '@/components/unitImageNull/unitImageNull.vue';
const animationRef1 = ref(null);
const router = useRouter();
const route = useRoute();
const props = defineProps({
  info: {
    type: Object,
  },
});

const store = useProjectStore();
const pathChild = (e: any) => {
  store.setchildModel(e);
  store.setCurrent(0);
  router.push({
    name: route.meta.loopType ? pathListLoop[8] : pathList[8],
    query: { childId: props.info.id },
  });
};
onMounted(() => {
  animation1();
});
const animation1 = () => {
  const observer = new IntersectionObserver((entries) => {
    let canTrigger = true; // 标记是否可以触发
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码
        animationRef1.value.classList.add('animation-box');
        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        // if (animationRef1.value) {
        //   animationRef1.value.classList.remove('animation-box');
        // }
      }
    });
  });
  observer.observe(animationRef1.value);
};
</script>

<style lang="less" scoped>
@import './index.less';
.boxs {
  padding-bottom: 80px;
  min-height: 632px;
}
.preface-box {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.preface-content {
  display: flex;
  width: 100%;
  cursor: pointer;
  // margin-top: 50px;
  box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.1);
  .preface-left {
    width: 600px;
    height: 358px;
    position: relative;
    overflow: hidden;
    .preface-left-img {
      width: 100%;
      height: 358px;
    }
  }
  .preface-right {
    flex: 1;
    // display: flex;
    // flex-direction: column;
    align-items: left;
    // justify-content: center;
    background-color: #fff;
    padding-left: 50px;
    padding-right: 50px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
}
.title1 {
  // width: 100%;
  display: inline;

  font-size: 20px !important;
  // font-weight: bold;
  font-family: SourceHanSerifCN-Bold;
}
.left-btn {
  width: 165px;
  height: 48px;
  margin-top: 0px;
  :deep(.iconfonts) {
    font-size: 48px !important;
  }
  :deep(.icon-flot) {
    width: 165px !important;
    height: 48px !important;
  }
}
.title {
  margin-bottom: 32px;
}
.left-title {
  text-indent: 2em;
  margin-bottom: 30px;
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden; //溢出内容隐藏
  text-overflow: ellipsis; //文本溢出部分用省略号表示
  display: -webkit-box; //特别显示模式
  -webkit-line-clamp: 3; //行数
  line-clamp: 3;
  -webkit-box-orient: vertical; //盒子中内容竖直排列
  line-height: 30px;
  font-size: 20px;
  color: #666;
  margin-top: 20px;
}
.text-max-box {
  width: 900px;
  margin: 20px 0 50px 0;
  line-height: 32px;
}
.line {
  width: 0px;
  height: 2px;
  background: #000;
  transform: all 0.5s;
}
.shadow {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  background: rgba(0, 0, 0, 0);
  transition: all 0.5s;
  z-index: 99;
}
.preface-content img {
  transition: all 0.5s;
}
.preface-content:hover img {
  transform: scale(1.1);
}
.preface-content:hover .shadow {
  background: rgba(0, 0, 0, 0.4);
}
</style>
